<?php
	/**
	 * 获取对应的评论
	 */
	function get_comments($ctype,$for_id,$pid){

		$comments = M('comments');
		$map['ctype'] = $ctype;
		$map['for_id'] = $for_id;
		$map['pid'] = $pid;
		/**
		**数据分页显示开始
		**/
		$count      = $comments->where($map)->count();// 查询满足要求的总记录数
		$Page       = new \Think\Page($count,40);// 实例化分页类 传入总记录数和每页显示的记录数(25)
		$Page->lastSuffix=false;
                    $Page->setConfig('header','<li class="rows">共<b>%TOTAL_ROW%</b>条记录&nbsp;&nbsp;每页<b>40</b>条&nbsp;&nbsp;第<b>%NOW_PAGE%</b>页/共<b>%TOTAL_PAGE%</b>页</li>');
                    $Page->setConfig('prev','上一页');
                    $Page->setConfig('next','下一页');
                    $Page->setConfig('last','末页');
                    $Page->setConfig('first','首页');
                    $Page->setConfig('theme','%FIRST% %UP_PAGE% %LINK_PAGE% %DOWN_PAGE% %END% %HEADER%');
		$show       = $Page->show();// 分页显示输出
		$sql = "SELECT fd_comments.*,fd_members.username AS username FROM fd_comments LEFT JOIN fd_members ON fd_comments.mid = fd_members.id where fd_comments.ctype=".$ctype." and fd_comments.for_id=".$for_id." and fd_comments.pid=".$pid." ORDER BY id desc LIMIT $Page->firstRow,$Page->listRows";
		$lists['lists'] = $comments->query($sql);
		// return $comments->getLastSql();
		/**
		**数据分页结束
		**/
		$lists['page_show'] = $show;

		return $lists;
	}


	/**
	 * 获取对应的收藏关注
	 */
	function get_collection($for_id,$ctype){

		$collections = M('collections');
		$map['ctype'] = $ctype;
		$map['for_id'] = $for_id;
		/**
		**数据分页显示开始
		**/
		$count      = $collections->where($map)->count();// 查询满足要求的总记录数
		$Page       = new \Think\Page($count,40);// 实例化分页类 传入总记录数和每页显示的记录数(25)
		$Page->lastSuffix=false;
                    $Page->setConfig('header','<li class="rows">共<b>%TOTAL_ROW%</b>条记录&nbsp;&nbsp;每页<b>40</b>条&nbsp;&nbsp;第<b>%NOW_PAGE%</b>页/共<b>%TOTAL_PAGE%</b>页</li>');
                    $Page->setConfig('prev','上一页');
                    $Page->setConfig('next','下一页');
                    $Page->setConfig('last','末页');
                    $Page->setConfig('first','首页');
                    $Page->setConfig('theme','%FIRST% %UP_PAGE% %LINK_PAGE% %DOWN_PAGE% %END% %HEADER%');
		$show       = $Page->show();// 分页显示输出
		$sql = "SELECT fd_collections.*,fd_members.username AS username FROM fd_collections LEFT JOIN fd_members ON fd_collections.mid = fd_members.id where fd_collections.ctype=".$ctype." and fd_collections.for_id=".$for_id." ORDER BY id desc LIMIT $Page->firstRow,$Page->listRows";
		$lists['lists'] = $collections->query($sql);
		// return $comments->getLastSql();
		/**
		**数据分页结束
		**/
		$lists['page_show'] = $show;

		return $lists;
	}
        
        
        /*
         * 调用微信的功能下发消息
         */
        function send_msg_with_wechat($mid,$content)
        {
            $DB_members = M('members');
            $openid = $DB_members->where(array('id' => $mid))->getField('wxopenid');
            
            if(!empty($openid))
            {
                
                $jssdk = new \Com\JSSDK(C('appid'), C('appsecret'));
                $accessToken = $jssdk->returnAccessToken();
        
                //初始化 对象
                $wxsdk = new \Com\WechatAuth(C('appid'), C('appsecret'),$accessToken);



                $wxsdk->sendText($openid, $content);
            }
            
            
        }

?>